﻿using System;
using System.Linq.Expressions;

namespace CommonServiceManager.Configuration
{
	/// <summary>
	/// A pair of and <see cref="Expression"/> to evaluate and an implementation key name (<see cref="string"/>).
	/// </summary>
	/// <typeparam name="TImplementation">The implementation <see cref="Type"/> we are configuring.</typeparam>
	public class KeyedPropertyExpression<TImplementation>
	{
		/// <summary>
		/// Create a new <see cref="Expression"/>/<see cref="string"/> pair.
		/// </summary>
		/// <param name="injectionPropertyExpression">The expression that specifies a property to inject.</param>
		/// <param name="implementationKey">The implementation key for a given implementation of the type of the property specified in <paramref name="injectionPropertyExpression"/></param>
		/// <exception cref="ArgumentNullException"><paramref name="injectionPropertyExpression"/> cannot be null</exception>
		public KeyedPropertyExpression(Expression<Func<TImplementation, object>> injectionPropertyExpression, string implementationKey = null)
		{
			if (injectionPropertyExpression == null) throw new ArgumentNullException("injectionPropertyExpression");

			InjectionPropertyExpression = injectionPropertyExpression;
			ImplementationKey = implementationKey;
		}

		/// <summary>
		/// The expression that specifies a property to inject.
		/// </summary>
		public Expression<Func<TImplementation, object>> InjectionPropertyExpression { get; set; }

		/// <summary>
		/// The implementation key for a given implementation of the type of the property specified in <see cref="InjectionPropertyExpression"/>
		/// </summary>
		public string ImplementationKey { get; set; }
	}
}